new Vue({
    el: '#app',
    data() {
        return {
            form: {
                Start_Date:'',
                End_Date:'',//状态
                page: 1,			//页数
                limit: 10			//每页数据条数
            },
            tableData: [],		//表格数据
            total: 1,
            MyDate: null,//根据时间筛选
            loading: false,
        }
    },
    mounted() {
        this.getList(this.form)
    },
    methods: {
        onSerach() {//查询方法 
            if (this.MyDate) {
                this.form.Start_Date = this.MyDate[0]
                this.form.End_Date = this.MyDate[1]
            } else {
                this.form.Start_Date = ''
                this.form.End_Date = ''
            }
            this.form.page = 1
            this.loading = true
            this.getList(this.form)
        },
        handleSizeChange(val) {
            this.form.page = 1;
            this.form.limit = val;
            this.getList(this.form)
        },
        handleCurrentChange(val) {
            this.form.page = val;
            this.getList(this.form);
        },
        getList(data) {     //换页方法
            let _this = this
            $.ajax({
                type: 'POST',
                url: DomainName + "/getReptileNewsAction?token=" + $.cookie('token'),
                data,
                complete: function (XMLHttpRequest) {
                    _this.loading = false
                    if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                        window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                    }
                },
                success: function (Result) {
                    _this.tableData = Result.tableData      //将获取的数据存到表格数据中
                    _this.total = Number(Result.limit)
                },
                dataType: "json"
            });
        },
        Show(Reptile_Main) {
            sessionStorage.setItem("Reptile_Main", Reptile_Main)
            window.location.href = './Show.html?Reptile_Main='+Reptile_Main
        },
        Delete(Reptile_Main_SerialNumber) {
            const _this = this
            this.$confirm('警告！此操作将删除此爬取新闻, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
                $.ajax({
                    url: DomainName + '/DeleteAction?token=' + $.cookie('token'),
                    type: 'POST',
                    data: {
                        TableName: 'reptile_info',
                        Primary_Key: Reptile_Main_SerialNumber,
                        Primary_Key_Name: 'Reptile_Main_SerialNumber',
                        Operation_Name: '删除爬取新闻'
                    },
                    success: function (res) {
                        if (res.Status == 'success') {
                            _this.getList(_this.form);
                            _this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                        }
                    },
                    complete: function (XMLHttpRequest) {
                        if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                            window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                        }
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'warning',
                    message: '已取消删除'
                });
            });
        },
    },
})